﻿#include "readfile_task.h"
#include <fstream>
#include <iostream>

ReadFileTask::ReadFileTask(const std::string &filename)
	: m_filename(filename)
	, m_result(0)
{

}

ReadFileTask::~ReadFileTask()
{

}

void ReadFileTask::Process(void *sharedObj)
{
	//this function run in multi mask's theads
	std::ifstream in(m_filename);
	if (in.is_open())
	{
		m_content.resize(1);
		in.read((char*)m_content.c_str(), m_content.size());
		m_result = 1;
	}
	else
	{
		std::cout << "can't open file, file name = " << m_filename << std::endl;
	}
}

void ReadFileTask::OnCompleted()
{
	//this function run in main thread
	std::cout << "read file completed!" << std::endl;
	std::cout << "result = " << m_result << ", content = " << m_content << std::endl;
}